/**
 * sysUserServiceImpl
 * 项目名称:分秒金融
 *
 * @author lunli
 *
 * 功能描述:系统用户管理
 * 
 * 历史版本:2017-03-28 v1.0.0 lunli  创建:
 * 
 */
package com.fmjr.sys.sysUser.service.impl;

import com.fmjr.common.base.exception.BusinessException;
import com.fmjr.common.base.util.Pager;
import com.fmjr.common.util.SqlUtil;
import com.fmjr.sys.sysUser.bean.SysUser;
import com.fmjr.sys.sysUser.dao.SysUserDao;
import com.fmjr.sys.sysUser.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;


@Service("sysUserService")
public class  SysUserServiceImpl implements ISysUserService {
	

	@Autowired
    private SysUserDao sysUserDao;

	/**
	 * 根据条件查询系统用户记录
	 * @author lunli
	 * @param  pager
	 * @return SysUserList
	 * @throws BusinessException
	 */
	public void selectSysUserList(Pager<SysUser> pager) throws BusinessException{
		int totalCount = sysUserDao.selectSysUserCount(pager);
		int numPerPage = SqlUtil.checkPageSize(pager.getNumPerPage());
		int currentPage = SqlUtil.checkPageCurrent(totalCount, numPerPage, pager.getPageNum());
		pager.setLimitStart(SqlUtil.countOffset(currentPage, numPerPage));
		pager.setPageSize(numPerPage);
		pager.setCurrentPage(currentPage);
		pager.setTotalCount(totalCount);
		pager.setTotalPage(totalCount%numPerPage==0?totalCount/numPerPage:totalCount/numPerPage+1);
		List<SysUser> list = sysUserDao.selectSysUserList(pager);
		pager.setList(list);
	}
	
	/**
	 * 根据ID查询系统用户记录
	 * @author lunli
	 * @param id
	 * @return domain
	 * @throws BusinessException
	 */
	public SysUser selectSysUserById(Long id) throws BusinessException{
		return sysUserDao.selectSysUserById(id);
	}

	/**
	 *  删除系统用户记录
	 * @author lunli	 
	 * @param id
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int deleteSysUserById(Long id) throws BusinessException{
		return sysUserDao.deleteSysUserById(id);
	}
	
	/**
	 * 修改系统用户记录
	 * @author lunli
	 * @param sysUser
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int updateSysUser(SysUser sysUser) throws BusinessException{
		sysUser.setUpdateDate(new Date());
		return sysUserDao.updateSysUser(sysUser);
	}

	/**
	 * 新增系统用户记录
	 * @author lunli
	 * @param sysUser
	 * @return
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int createSysUser(SysUser sysUser) throws BusinessException{
		sysUser.setCreateDate(new Date());
		return sysUserDao.createSysUser(sysUser);
	}

	@Override
	public SysUser findByUsername(String username) throws BusinessException {
		SysUser s = sysUserDao.findByUsername(username);
		return s;
	}
	

	

}
